<template>
	<div class="personal">
		<el-form label-width="100px" ref="editForm" :model="editForm" :rules="rules">
			<el-form-item  label="班级名" prop="banjiming"><el-input size="small" v-model="editForm.banjiming" auto-complete="off" placeholder="请输入班级名" style='width:50%'></el-input></el-form-item>
		<el-form-item  label="专业" prop="zhuanye"><el-input size="small" v-model="editForm.zhuanye" auto-complete="off" placeholder="请输入专业" style='width:50%'></el-input></el-form-item>
		<el-form-item  label='用户名' prop='yonghuming'><el-select size='small' v-model='editForm.yonghuming' placeholder='请选择用户名' @change="hsgxia2suiyonghuming"><el-option selected label='请选择用户名' value=''></el-option><el-option v-for="item in xueshengxinxis" :key="item.yonghuming" :label="item.yonghuming" :value="item.yonghuming"></el-option></el-select></el-form-item>
		<el-form-item  label="姓名" prop="xingming"><el-input size="small" v-model="editForm.xingming" auto-complete="off" placeholder="" style='width:50%' disabled></el-input></el-form-item>
		<el-form-item  label="手机" prop="shouji"><el-input size="small" v-model="editForm.shouji" auto-complete="off" placeholder="请输入手机" style='width:50%'></el-input></el-form-item>
		<el-form-item  label="工号" prop="gonghao"><el-input size="small" v-model="editForm.gonghao" auto-complete="off" placeholder="请输入工号" style='width:50%' disabled></el-input></el-form-item>
		<el-form-item  label="教师姓名" prop="jiaoshixingming"><el-input size="small" v-model="editForm.jiaoshixingming" auto-complete="off" placeholder="请输入教师姓名" style='width:50%' disabled></el-input></el-form-item>
		<el-form-item  label="职称" prop="zhicheng"><el-input size="small" v-model="editForm.zhicheng" auto-complete="off" placeholder="请输入职称" style='width:50%' disabled></el-input></el-form-item>

		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">添加</el-button>
		</div>
	</div>
</template>

<script>
	import {zaixianfenbanEdit, zaixianfenbanSave,zaixianfenbanDetail} from "@/api/zaixianfenban/zaixianfenbanApi";
	import {Session} from "@/utils/storage";
import {jiaoshixinxiDetail,jiaoshixinxiEdit} from "../../api/jiaoshixinxi/jiaoshixinxiApi";
import {xueshengxinxiAllList,xueshengxinxiList} from "@/api/xueshengxinxi/xueshengxinxiApi";
				//xiabiaoduan1
export default {
	name: 'personal',
	data() {
		return {
			rules: {
				//yztssssss1
			},
			editForm: {
				avater:'',
				gonghao:'',
				jiaoshixingming:'',
				zhicheng:'',

			},
			username:'',
			cx:'',
			xueshengxinxis:[],
				//xiabiaoduan2
		};
	},
	created() {
		if (!Session.get('userInfo')) return false;
		this.userInfo = Session.get('userInfo');
		this.username=localStorage.getItem("username");
		this.cx=localStorage.getItem("cx");
		let id = this.$route.params.id;
		this.getAllxueshengxinxi({});
				//xiabiaoduan3
		this.getUserInfo(id);
	},
	computed: {
		headers(){
			return {"token":Session.get("token")}
		},
	},
	methods:{
		getUserInfo(id){
			jiaoshixinxiDetail(id).then(res=>{
				if(res.code == '0'){
					this.jiaoshixinxi = res.data
					this.editForm.gonghao = this.jiaoshixinxi.gonghao;
					this.editForm.jiaoshixingming = this.jiaoshixinxi.jiaoshixingming;
					this.editForm.zhicheng = this.jiaoshixinxi.zhicheng;




				}
			})
		},

		//qixuzhijixsuan3
		hsgxia2suiyonghuming(){
			let yonghuming = this.editForm.yonghuming;
			this.xueshengxinxis.forEach(item=>{
				if(item.yonghuming == yonghuming){
					this.editForm.xingming = item.xingming
					this.editForm.shouji = item.shouji


					//kuabiaogaizhi31
					this.$forceUpdate()
				}
			})
		},
		// 编辑、增加页面保存方法
		submitForm(editData) {

			this.$refs[editData].validate(valid => {
				if (valid) {
					if(this.editForm.id){

					}else {
						zaixianfenbanSave(this.editForm).then(res => {
							if (res.code == '0') {

								this.$message({
									type: 'success',
									message: '添加成功！'
								})
							} else {
								this.$message({
									type: 'info',
									message: res.msg
								})
							}
						}).catch(err => {
							if(err){
								this.$message.error(err)
							}else {
								this.$message.error('操作失败，请稍后再试！')
							}
						})
					}
				} else {
					return false
				}
			})
		},

		//youscwexnjiaxn
		getAllxueshengxinxi(parameter){xueshengxinxiList(parameter).then(res=>{if(res.code == '0'){this.xueshengxinxis = res.data.list}})},
				//xiabiaoduan4
	}
};
</script>

<style scoped lang="scss">
	@import './index.scss';
</style>
